const express = require('express')
//创建app
const app = express()
//监听9090端口
app.listen(9090,function(){
  console.log(`
    Node app start at 9090
  `)
})
app.get('/',function(req,res){
  res.json({
    name: 'Jarry',
    age: 12
  })
})

const mongoose = require('mongoose')

const DB_URL = 'mongodb://127.0.0.1:27017'
mongoose.connect(DB_URL)
mongoose.connection.on('connected',function(){
  console.log('Mongoose start at 27017')
})
const User = mongoose.model('user',new mongoose.Schema({
  name: {
    type: String,
    require: true
  },
  age: {
    type: Number,
    require: true
  }
}))

/* User.create({
  name: 'Tom',
  age: 90
}, function(err, doc){
  if(!err){
    console.log(doc)
  }else{
    console.log(err)
  }
}) */
User.update({name:''},{$set:{
  name: 'Jarry'
}},function(err, doc){
  if( !err ){
    console.log(doc)
  }else{
    console.log(err)
  }
})
app.get('/data',function(req, res){
  User.find({},function(err, doc){
    res.json(doc)
  })
})